home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-05-18 | 3.6 KB | 93 lines | [TEXT/GEOL] |
- Item forwarded by PHAC to DOUGLASS1 MEIER1
-
- Item 7027909 15-May-90 14:20PDT
-
- From: CDA0004 VAR Shana Corp, Don Murphy,IVR
-
- To: MACDTS Macintosh Developer Tech Supt
- MACAPP.TECH$ MacApp Technical
- CAN.DTS Canada Development Support Group
-
- Sub: UnloadAllSegs
-
- Attn: Keith Rollin
- Attn: MacApp.Tech$
- Attn: Canada DTS
- SentBy: Wayne Malkin
- Date 5/14/90
- Subject UnloadAllSegs
- From Wayne Malkin
- To Keith Rollin
- Canada DTS
- MacApp.Tech$
-
- Memo Subject:UnloadAllSegs
-
- Keith,
-
- Here is an update on the UnloadAllSegs hack I sent to you some months back.
-
-
- The Story So Far:
-
- To refresh everyone's memory, the idea was to patch LoadSeg and monitor the
- amount of code that is loaded before attempting to load another segment. If
- the loaded code exceeded some value, the LoadSeg patch would call
- UnloadAllSegs before loading the requested segment.
-
- To make this work, UnloadAllSegs was modified to do a stack crawl and
- determine what segments were in the current call chain. These segments would
- not be unloaded. The effect of all this is to reduce the maximum loaded code
- by at least 50%.
-
- When UnloadAllSegs is only called from the main event loop, the maximum amount
- of loaded code is the sum of all segments that get called as a result of a
- single user action. When UnloadAllSegs is called from the LoadSeg patch as
- well, the maximum drops to the maximum length of a single chain.
-
- The first problem was that the stack frames are not consistent when LoadSeg
- gets called from the jump table. Because no LINK instruction is performed in
- the jump table, there is no reference to the routine that called into the jump
- table. I faked up a stack frame in the LoadSeg patch to work around that
- problem.
-
-
- This Week's Episode:
-
- This "hack" has been working beautifully in a shipping product (600 copies
- sold so far) for 3 months. While working on the next release, I found an
- additional nasty problem. (luckily, it's not in the current release...)
-
- The problem is in the failure mechanism. CatchFailures saves registers,
- including A6, and Failure restores these registers before calling the failure
- handler procedure. This is ok as long as the failure handler is local to some
- procedure that is still in the call chain. The stack frames are all correct.
-
- However, if the failure handler is in the global scope, there is a good chance
- that the stack frames will have gone away.
-
- In my example, a CatchFailures was done in a global routine, with another
- global routine as the failure handler. Once the routine that posted the
- CatchFailures returns to its caller, the A6 that was saved for the failure
- handler becomes invalid. Since it is a global routine, that is not
- particularly relevant, except that if UnloadAllSegs gets called from this
- failure handler (as a result of a LoadSeg), there is no way to determine what
- segments are still in the call chain, because there is no valid stack crawl.
-
- The only solution I could come up with on short notice was to use a global to
- disable the unloading of segments while the global failure handler was
- executing.
-
- Since there is nowhere for the failure handler to go, it might be possible to
- determine the stack frames by looking at the saved value of A6 in the next
- failure handler. I didn't play around with this, though.
-
- Apart from this one problem, everything has been working GREAT for a few
- months. The benefits are immense, since our maxiumum code reserve dropped from
- 450k down to 140k.
-
-
- -- Wayne Malkin
-
-
-